/*package itsm.isperp.framework.message.impl;

import itsm.isperp.framework.core.context.ContextHolder;
import itsm.isperp.framework.message.IMessageSender;
import itsm.isperp.framework.message.domain.IMessagePacket;

import java.io.File;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.Properties;

import javax.activation.DataHandler;
import javax.activation.DataSource;
import javax.activation.FileDataSource;
import javax.mail.Authenticator;
import javax.mail.Multipart;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
import javax.mail.internet.MimeUtility;

import microsoft.exchange.webservices.data.core.ExchangeService;
import microsoft.exchange.webservices.data.core.enumeration.misc.ExchangeVersion;
import microsoft.exchange.webservices.data.core.enumeration.property.BodyType;
import microsoft.exchange.webservices.data.core.service.item.EmailMessage;
import microsoft.exchange.webservices.data.credential.ExchangeCredentials;
import microsoft.exchange.webservices.data.credential.WebCredentials;
import microsoft.exchange.webservices.data.property.complex.MessageBody;

import org.apache.commons.lang3.StringUtils;

public class EmailExchangeSender implements IMessageSender {

	public static final String BEAN_ID = "isperp.emailSender";
	private Session session;

	private static boolean SESSION_REFRESH = false;

	public static void refreshCache() {
		SESSION_REFRESH = true;
	}

	@Override
	public void send(IMessagePacket message) throws Exception {
		this.sendMail(message, null);
	}

	*//**
	 * 发送邮件
	 * 
	 * @param message
	 * @param files
	 * @throws Exception
	 *//*
	public void sendMail(IMessagePacket message, Collection<File> files)
			throws Exception {
		System.out.print("--------------邮件发送--------------");
		System.out.print(message);

		if (message.getTitle() != null) {			
			 ExchangeService service = new ExchangeService(
		        ExchangeVersion.Exchange2007_SP1);
			 String user = ContextHolder.getConfigByKey("readMailUser"), pwd = ContextHolder
		        .getConfigByKey("readMailPassword");
		    ExchangeCredentials credentials = new WebCredentials(user, pwd, "mo-co");
		    service.setCredentials(credentials);
		    service.setTraceEnabled(true);
		    try {
		      service.setUrl(new URI("https://mail.mo-co.com/EWS/Exchange.asmx"));
		    } catch (URISyntaxException e) {
		      e.printStackTrace();
		    }
		    String subject=MimeUtility.encodeText(message.getTitle(),
	          "UTF-8", "B");
		    String Content_ = message.getContent();
		    
		    EmailMessage msg = new EmailMessage(service);
		    msg.setSubject(subject);
		    MessageBody body = MessageBody.getMessageBodyFromText(Content_);
		    body.setBodyType(BodyType.HTML);
		    msg.setBody(body);
		    String[] to={message.getReceiverAddress()};
		    for (String s : to) {
		      msg.getToRecipients().add(s);
		    }
		    msg.send();
		}
	}

	*//**
	 * 获取有效的缓存
	 * 
	 * @return
	 *//*
	private Session getMailSession() {
		if (session == null || SESSION_REFRESH == true) {
			resetSession();
		}
		return session;
	}

	private void resetSession() {

		SESSION_REFRESH = false;
		Properties properties = new Properties();
		properties.put("mail.transport.protocol", "smtp");
		properties.put("mail.smtp.auth", "true");
		properties.setProperty("mail.smtp.ssl.enable", "true");
		properties.put("mail.host", ContextHolder.getConfigByKey("mailServer")); 

		session = Session.getInstance(properties, new Authenticator() {
			public PasswordAuthentication getPasswordAuthentication() {
				return new PasswordAuthentication(ContextHolder.getConfigByKey(
						"mailAccount"), ContextHolder
						.getConfigByKey("mailPassword"));
			}
		});
	}
}
*/